package com.azkj.album.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import androidx.annotation.Nullable;

import com.azkj.album.R;
import com.azkj.album.network.ConfigStorage;


public class SplashActivity extends Activity {

    String[] imgs = new String[]{
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farticle%2F4f13a4953601b7d6ab583453c33071d24263a2f2.jpg&refer=http%3A%2F%2Fi0.hdslb.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1640249009&t=ede604aec0925021a849a53537e6d244",
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201707%2F23%2F20170723131756_di5rv.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1640249009&t=18d9f9faf5a666ae06ba4f371a8ed104",
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.zhimg.com%2F50%2Fv2-db1b4c0d0f38add8eff79e73c3fc1353_hd.jpg&refer=http%3A%2F%2Fpic1.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1640249009&t=a336253f65ab5aa99b0589a901a07558",
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic2.zhimg.com%2F50%2Fv2-e4235786bbfa121e3410ca7df364a0e7_hd.jpg&refer=http%3A%2F%2Fpic2.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1640249009&t=f584a42a311c1f519dc007450f77088a"
    };


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        new Handler().postDelayed(() -> {
            startActivity();
        }, 500);
    }

    private void startActivity() {
        Intent intent = null;
        if (ConfigStorage.getInstance().isLogin()) {
            intent = new Intent(this, HomeActivity.class);
            setPushIntentData(intent);
        } else {
            intent = new Intent(this, LoginActivity.class);
        }
        startActivity(intent);
        finish();
    }


    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(0, 0);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setPushIntentData(intent);
    }

    /**
     * 设置推送的信息
     *
     * @param intent
     */
    private void setPushIntentData(Intent intent) {
        try {
            intent.setData(getIntent().getData());
            if (getIntent().hasExtra(HomeActivity.PUSH_MESSAGE)) {
                intent.putExtra(HomeActivity.PUSH_MESSAGE, getIntent().getStringExtra(HomeActivity.PUSH_MESSAGE));
            }
        } catch (Exception e) {
        }
    }
}
